<?php
include_once("../configure/admin.config.inc.php");//--> admin global var
include_once("db.inc.php");						//--> db global var

include_once("Operation.php");					//--> Operation
include_once("MenuGroup.php");					//--> Menu group class
include_once("Menu.php");						//--> Menu  class
require_once("controlHeader.php");				//--> system control header

$objOperate		= new Operation($objSession->getLanguage());		//--> Operation instance
$objMenuGroup 	= new MenuGroup($objSession->getLanguage(), $uid);	//--> Menu group instance
$objMenu 		= new Menu($objSession->getLanguage(), $uid);		//--> Menu instance

$arrOperate 	= $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);


if(isset($_GET['id']) && !empty($_GET['id'])){
	$id = $_GET['id'];

	if($gid == $id){
		$error_message = 'invalid delete menu group.';
	}else if(count($objMenu->lists($arrOperate, " WHERE groupid=$id", 1, 1, '')) > 0) {
		$error_message = "can't delete the user group, because that have user above the user group.";
	}else{
		$isReturn = $objMenuGroup->delete($arrOperate, $id);
		if($isReturn)
			$error_message = 'delete group successfully.';
		else 
			$error_message = 'delete group fail.';
	}
}

echo "<script language='javascript'>";
echo "alert(\"$error_message\");";
echo "location.href=\"".$_SERVER['HTTP_REFERER']."\";";
echo "</script>";

//$backurl = $_SERVER['HTTP_REFERER'];
//header("Location: $backurl");
?>
